from functools import wraps
import ffmpeg
import os
from Statistics.COMMON import ALL_EXTTS
from Service.MyLogger import MyLogger
import os,logging
logFileName =  os.path.basename(__file__).split(".")[0]
from Statistics.COMMON import commonLogger
log = commonLogger # MyLogger(r"./Logs/%s.log" % (logFileName), logging.DEBUG, logging.DEBUG)
def a_new_decorator(a_func):
    @wraps(a_func)
    def wrapTheFunction(*args, **kwargs):
        log.info("I am doing some boring work before executing a_func()")
        a_func(*args, **kwargs)
        log.info("I am doing some boring work after executing a_func()")
    return wrapTheFunction

def for_decorator(a_func):
    @wraps(a_func)
    def wrapTheFunction(*args, **kwargs):
        for i in range(3):
            a_func(*args, **kwargs)
    return wrapTheFunction

def getVideoInfoDecorator(a_func):
    @wraps(a_func)
    def wrapTheFunction(filePaths,*args, **kwargs):
        filePathArr = filePaths.strip('\n').split('\n')
        for filePath in filePathArr:
            filePath = filePath.replace("%23", "#")
            path, fileName = os.path.split(filePath)
            path = path.strip('\n')
            fileName = fileName.strip('\n')

            stream = ffmpeg.input(filePath)
            (fileNa, extension) = os.path.splitext(fileName)
            if ALL_EXTTS.find(extension) < 0:
                return "TypeError"
            log.info("fileName:", fileName)
            a_func(filePaths,*args, **kwargs)(filePath)
    return wrapTheFunction

def getFileInfoDecorator(a_func):
    @wraps(a_func)
    def wrapTheFunction(filePaths,*args, **kwargs):
        filePathArr = filePaths.strip('\n').split('\n')
        for filePath in filePathArr:
            filePath = filePath.replace("%23", "#")
            path, fileName = os.path.split(filePath)
            path = path.strip('\n')
            fileName = fileName.strip('\n')

            stream = ffmpeg.input(filePath)
            (fileNa, extension) = os.path.splitext(fileName)
            if ALL_EXTTS.find(extension) < 0:
                return "TypeError"
            log.info("fileName:", fileName)
            a_func(filePaths,*args, **kwargs)(filePath)
    return wrapTheFunction